package com.qinyh.view;

import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.qinyh.entity.BookCatalog;

public class MyAdapter extends BaseAdapter {

	private List<BookCatalog> catalog;
    private Activity activity;
    public void setActivity(Activity activity){
    	this.activity = activity;
    }
	
	public List<BookCatalog> getCatalog() {
		return catalog;
	}
	public void setCatalog(List<BookCatalog> catalog) {
		this.catalog = catalog;
	}

	private Context ctt;

	public void setConext(Context context) {
		this.ctt = context;
	}

	@Override
	public int getCount() {
		return catalog.size();
	}

	@Override
	public Object getItem(int position) {
		return catalog.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		CatalogView tv = new CatalogView(ctt);
		tv.setActivity(activity);
		tv.setCatalog(catalog.get(position));
		tv.setBackgroundResource(catalog.get(position).getId());
		tv.setEnabled(true);
		return tv;
	}

}
